Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 18, 2025

Description

PHP 8.5 | Tokenizer/PHP: polyfill the (void) cast

As part of the RFC for the #[NoDiscard] attribute, a new typecast (void) has been introduced.

This commit polyfills this new token for PHP < 8.5.

Includes tests covering the complete set of type casts, even though the PHPCS Tokenizer only handles the (void) cast.
Reason being, that PHP has deprecated and removed some casts, like (unset), and their token constants may be removed from PHP Core at some point in the future. These tests should serve as a warning system for that eventuality.

Ref: https://wiki.php.net/rfc/marking_return_value_as_important#void_cast_to_suppress_the_warning

Various sniffs: add tests with PHP 8.5 (void) cast

Suggested changelog entry

Added

  • Tokenizer support for the new PHP 8.5 (void) cast.
    • The T_VOID_CAST token has been added to the Tokens::CAST_TOKENS array.

Related issues/external references

Related to #1306

@jrfnl
Copy link
Member Author

jrfnl commented Nov 18, 2025

Rebased without changes to get a passing build after #1326

As part of the RFC for the `#[NoDiscard]` attribute, a new typecast `(void)` has been introduced.

This commit polyfills this new token for PHP < 8.5.

Includes tests covering the complete set of type casts, even though the PHPCS Tokenizer only handles the `(void)` cast.
Reason being, that PHP has deprecated and removed some casts, like `(unset)`, and their token constants may be removed from PHP Core at some point in the future. These tests should serve as a warning system for that eventuality.

Ref: https://wiki.php.net/rfc/marking_return_value_as_important#void_cast_to_suppress_the_warning
@jrfnl
Copy link
Member Author

jrfnl commented Nov 24, 2025

Rebased without changes, other than squashing the "fix up" commits into their atomic ancestors.

@jrfnl jrfnl force-pushed the php-8.5/1306-tokenizer-php-polyfill-void-cast branch from 1f25f50 to dc30ab9 Compare November 24, 2025 08:38
@jrfnl jrfnl merged commit c4adbbc into 4.x Nov 24, 2025
79 checks passed
@jrfnl jrfnl deleted the php-8.5/1306-tokenizer-php-polyfill-void-cast branch November 24, 2025 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants